package org.nabc.generate.controller;

import lombok.extern.slf4j.Slf4j;
import org.nabc.configuration.FileConfiguration;
import org.nabc.constant.ModeConstant;
import org.nabc.constant.TypeConstant;
import org.nabc.generate.AbstractRunnableTask;
import org.nabc.support.PropertyValues;

@Slf4j
public class GoControllerTemplateGenerateTask extends AbstractRunnableTask {
    @Override
    public void setParameters(FileConfiguration fileConfiguration, PropertyValues propertyValues) {
        this.fileSuffix = "go";

        fileTemplateData = inputFromFile("src/main/resources/template/go/controller/Controller.template");

        super.setParameters(fileConfiguration, propertyValues, "controller");
    }

    @Override
    public void setModelAndType() {
        this.type = TypeConstant.CONTROLLER;
        this.mode = ModeConstant.GO;
    }

    @Override
    public void generate() throws Exception {
        String mapperFileData = fileTemplateData.toString()
                .replace("#{packageName}", fileConfiguration.getPackageName())
                .replace("#{entityClass}", entityName)
                .replace("#{entityName}", lowerLetter(entityName));

        outputToFile(mapperFileData, filePath);
    }
}
